package com.veer.shop.controller.front;

import com.veer.shop.service.impl.front.CustomerServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.veer.shop.annotation.ApiControllerLog;
import com.veer.shop.annotation.ApiSecured;
import com.veer.shop.annotation.CurrentCustomer;
import com.veer.shop.config.ApiUrlConfig;
import com.veer.shop.pojo.CurrentCustomerInfo;
import com.veer.shop.pojo.CustomerLogin;
import com.veer.shop.pojo.RegisterCustomer;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.impl.admin.AuthorizeServiceImpl;
import com.veer.shop.service.impl.admin.PhoneServiceImpl;

/**
 * 客户控制器
 * 
 * @author WangBin
 * 2020年12月1日-下午5:55:54
 */
@RestController
public class CustomerController {
	@Autowired
	private AuthorizeServiceImpl authorizeServiceImpl;
	@Autowired
	private CustomerServiceImpl customerServiceImpl;
	@Autowired
	private PhoneServiceImpl phoneServiceImpl;
	
	/**
	 * 获取会员Token
	 */
	@RequestMapping( path = ApiUrlConfig.API_CUSTOMER_TOKEN_URL, method = RequestMethod.POST)
	public ResponseData<?> getCustomerToken(@RequestBody CustomerLogin customerLogin)
	{
		return authorizeServiceImpl.getCustomerToken(customerLogin);
	}

	/**
	 * 获取验证码
	 *
	 * @param customer
	 * @return
	 */
	@ApiControllerLog(description = "获取验证码")
	@RequestMapping( path = ApiUrlConfig.API_GET_PHONE_VCODE_URL, method = RequestMethod.GET)
	public ResponseData<?> register(@Param("phone")String phone) {
		return phoneServiceImpl.getVCode(phone);
	}
	
	/**
	 * 会员注册
	 *
	 * @param customer
	 * @return
	 */
	@ApiControllerLog(description = "会员注册")
	@RequestMapping( path = ApiUrlConfig.API_CUSTOMER_REGISTER_URL, method = RequestMethod.POST)
	public ResponseData<?> register(@RequestBody RegisterCustomer customer) {
		return customerServiceImpl.register(customer);
	}
	
	/**
	 * 会员注销登录
	 *
	 * @return
	 */
	@ApiSecured(isAdmin = false)
	@ApiControllerLog(description = "会员退出登录")
	@RequestMapping(path = ApiUrlConfig.API_CUSTOMER_LOGINOUT_URL, method = RequestMethod.POST)
	public ResponseData<?> loginOut(@CurrentCustomer CurrentCustomerInfo currnetCustomer) {
		return customerServiceImpl.loginOut(currnetCustomer);
	}
}
